#include <EIKENV.H>
#include <GDI.H>
#include "WaittingBar.h"
#include "CGifPicture.h"
#include "CPainter.h"

CWaittingBar::CWaittingBar(CPainter* aPainter)
{
	iPainter = aPainter;
}

CWaittingBar* CWaittingBar::NewL( CPainter* aPainter, const TRect& aRect )
{
    CWaittingBar* self = CWaittingBar::NewLC( aPainter, aRect );
    CleanupStack::Pop( self );
    return self;
}

// -----------------------------------------------------------------------------
// CTestMe2AppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CWaittingBar* CWaittingBar::NewLC( CPainter* aPainter, const TRect& aRect )
{
    CWaittingBar* self = new ( ELeave ) CWaittingBar(aPainter);
    CleanupStack::PushL( self );
    self->ConstructL( aRect );
    return self;
}

void CWaittingBar::ConstructL( const TRect& aRect )
{
    // Create a window for this application view
    CreateWindowL();

    // Set the windows size
    SetRect( aRect );

    iGif = new CGifPicture(*this);
    iGif->LoadFileL(_L("c:\\gif\\test01.gif"));
    
    ActivateL();
    
}
    
CWaittingBar::~CWaittingBar()
{
	delete iGif;
}

void CWaittingBar::Draw( const TRect& aRect) const
{
    // Get the standard graphics context
    CWindowGc& gc = SystemGc();

	gc.SetPenColor	(TRgb(0,0,255));
	gc.SetBrushColor(TRgb(165,174,0));	
    // Gets the control's extent
    //TRect drawRect( Rect());

    // Clears the screen
    //gc.Clear( drawRect );

	//draw background
	TRect rc(aRect);
	//rc.Move(10,0);
	iPainter->Draw(gc, rc);

	//draw text    
	const CFont* font = CEikonEnv::Static()->DenseFont();
	gc.UseFont( font);
	TBuf<10> text;
	text.Copy(_L("test"));

	int baseline =	font->AscentInPixels() + 3;
    gc.DrawText(text, aRect, baseline, CGraphicsContext::ELeft, 1);	
	gc.DiscardFont();		    
	
	//draw the gif
	TSize aSize;
	iGif->GetSize(aSize);
	
	TRect rect(aSize);
	int offsetx = (Rect().Width()-rect.Width())/2; 
	int offsety = (Rect().Height()-rect.Height())/2; 
	rect.Move(offsetx, offsety);
	iGif->DrawFrame(gc, rect);
}

void CWaittingBar::SimpleWait()
{

}